//
//  ColumnTableViewCell.m
//  Project_B
//
//  Created by 张闯的mac pro on 15/11/28.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "ColumnTableViewCell.h"
#import "FirstModel.h"
#import "UIImageView+WebCache.h"

@interface ColumnTableViewCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *imageView1;
@property (nonatomic, strong) UIImageView *imageView2;
@property (nonatomic, strong) UIImageView *imageView3;
@property (nonatomic, strong) UIImageView *headImageView;
@property (nonatomic, strong) UILabel *nickLabel;
@property (nonatomic, strong) UILabel *replayLabel;

@end


@implementation ColumnTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [[UILabel alloc] init];
        [self.titleLabel setFont:[UIFont systemFontOfSize:16]];
        self.titleLabel.textColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1];
        [self.contentView addSubview:self.titleLabel];
        
        self.imageView1 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView1];
        CALayer *layer = [self.imageView1 layer];
        layer.borderColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1].CGColor;
        layer.borderWidth = 1;
        
        self.imageView2 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView2];
        CALayer *layer2 = [self.imageView2 layer];
        layer2.borderColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1].CGColor;
        layer2.borderWidth = 1;
        
        self.imageView3 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView3];
        CALayer *layer3 = [self.imageView3 layer];
        layer3.borderColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1].CGColor;
        layer3.borderWidth = 1;
        
        self.headImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.headImageView];
        CALayer *layer4 = [self.headImageView layer];
        layer4.borderColor = [UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1].CGColor;
        layer4.borderWidth = 1;
        
        self.nickLabel = [[UILabel alloc] init];
        [self.nickLabel setFont:[UIFont systemFontOfSize:14]];
        self.nickLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.nickLabel];
        
        self.replayLabel = [[UILabel alloc] init];
        [self.replayLabel setFont:[UIFont systemFontOfSize:14]];
        self.replayLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.replayLabel];
        
    }
    
    return self;
}

- (void)setModel:(FirstModel *)model
{
    if (_model != model) {
        _model = model;
    }
    
    self.titleLabel.text = model.topic_title;
    NSArray *arr = (NSArray *)model.topicimagelist;
    
    if (arr.count == 3) {

        [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:arr[0][@"images"]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:arr[1][@"images"]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
        [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:arr[2][@"images"]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
    } else {
        [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:arr[0][@"images"]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
    }
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headicon] placeholderImage:[UIImage imageNamed:@"zhanwei"]];


    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headicon] placeholderImage:[UIImage imageNamed:@"zhanwei"]];    

    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headicon] placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];

    
    self.nickLabel.text = model.nickname;
    self.replayLabel.text = [NSString stringWithFormat:@"%@回复", model.replytotal];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(5, 5, 375 - 10, 20);
    self.imageView1.frame = CGRectMake(10, 30, 110, 80);
    self.imageView2.frame = CGRectMake(130, 30, 110, 80);
    self.imageView3.frame = CGRectMake(250, 30, 110, 80);
    self.headImageView.frame = CGRectMake(10, 120, 30, 30);
    self.nickLabel.frame = CGRectMake(43, 120, 130, 30);
    self.replayLabel.frame = CGRectMake(320, 120, 70, 30);
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
